/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Init.java
 *
 * Created on 23-sep-2011, 21:45:08
 */
package Principal.regresion;

import java.awt.HeadlessException;
import librerias.regresion.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.util.TableOrder;

/**
 *
 * @author JONATHAN
 */
public class FRame_Regresion extends javax.swing.JFrame {

    public DefaultTableModel miModelo;
    public String[][] data = {};
    ArrayList arreglo = new ArrayList();
    ArrayList arreglo_pronostico = new ArrayList();
    public int periodos, elementos_periodo;
    double y_promedio;
    double suma = 0;
    EscalaMovil escal = new EscalaMovil();
    static ListaDobleConOrden ldco = new ListaDobleConOrden();
// Creamos y rellenamos el modelo de datos
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String tipo_cuadro = "", periodo = "", valorY = "", nombre_linea = "Grafico de puntos ingresados";

    /** Creates new form Init */
    JTable getMiTabla() {
        return Tabla;
    }

    public DefaultTableModel getMiModelo() {
        return miModelo;
    }

    public FRame_Regresion() {
        initComponents();
        setLocationRelativeTo(null);
        PPeriodo.setValue(1);
        EEPeriodo.setValue(1);
        miModelo = new DefaultTableModel(data, new String[]{""}) {
        };
        Tabla.setModel(miModelo);
        jScrollPane1.setViewportView(Tabla);
    }

    private void GENERAR_VENTANA() throws HeadlessException {
        JFreeChart chart = null;
        chart = createChart(dataset, TiposDeGrafico.LineChart);
        //De esta manera es el grafico de lineas
        Resultados objeto = new Resultados(chart, ldco);
        objeto.show();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tabla = new javax.swing.JTable();
        PPeriodo = new javax.swing.JSpinner();
        EEPeriodo = new javax.swing.JSpinner();
        GTabla = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        Line_const = new javax.swing.JMenuItem();
        Line_Asc = new javax.swing.JMenuItem();
        MEnu_Ciclico = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        Metodo_multiple = new javax.swing.JCheckBoxMenuItem();
        Menu_Multiple = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Periodos");

        jLabel2.setText("Elementos por periodo");

        Tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(Tabla);

        GTabla.setText("Generar tabla");
        GTabla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GTablaActionPerformed(evt);
            }
        });

        jMenu1.setText("Metodos");

        Line_const.setText("Lineal Constante");
        Line_const.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Line_constActionPerformed(evt);
            }
        });
        jMenu1.add(Line_const);

        Line_Asc.setText("Lineal Ascendente");
        Line_Asc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Line_AscActionPerformed(evt);
            }
        });
        jMenu1.add(Line_Asc);

        MEnu_Ciclico.setText("Lineal Ciclico");
        MEnu_Ciclico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MEnu_CiclicoActionPerformed(evt);
            }
        });
        jMenu1.add(MEnu_Ciclico);

        jMenuItem1.setText("Salir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Regresion multiple");

        Metodo_multiple.setText("Modificar Parametros");
        Metodo_multiple.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Metodo_multipleActionPerformed(evt);
            }
        });
        jMenu2.add(Metodo_multiple);

        Menu_Multiple.setText("Mostrar Resultados");
        Menu_Multiple.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Menu_MultipleActionPerformed(evt);
            }
        });
        jMenu2.add(Menu_Multiple);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(PPeriodo, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(EEPeriodo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE))
                        .addGap(57, 57, 57)
                        .addComponent(GTabla)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(PPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(GTabla)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(EEPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void GTablaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GTablaActionPerformed
    periodos = Integer.parseInt(PPeriodo.getValue().toString());
    elementos_periodo = Integer.parseInt(EEPeriodo.getValue().toString());

    if (Metodo_multiple.isSelected()) {
        Object[] titulos = new Object[4];
        titulos[0] = "Número de periodo";
        titulos[1] = "Resultado Y";
        titulos[2] = "Variable X 1";
        titulos[3] = "Variable X 2";
        getMiModelo().setColumnIdentifiers(titulos);
        getMiModelo().setColumnCount(4);
        getMiModelo().setRowCount(periodos);
        for (int i = 0; i < getMiModelo().getRowCount(); i++) {
            getMiTabla().setValueAt(i + 1, i, 0);
        }
    } else {
        if (elementos_periodo != 0 && periodos != 0) {
            Object[] titulos = new Object[periodos + 1];
            titulos[0] = "Número de periodo";
            for (int i = 1; i <= periodos; i++) {
                titulos[i] = "Periodo" + String.valueOf(i);
            }
            getMiModelo().setColumnIdentifiers(titulos);
            getMiModelo().setColumnCount(periodos + 1);
            getMiModelo().setRowCount(elementos_periodo);

            for (int i = 0; i < getMiModelo().getRowCount(); i++) {
                getMiTabla().setValueAt(i + 1, i, 0);
            }

        }
    }
}//GEN-LAST:event_GTablaActionPerformed

private void Line_constActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Line_constActionPerformed
//Generar array
    arreglo.clear();
    arreglo_pronostico.clear();
    ldco.setInicio(null);
    AsignarArreglo();
}//GEN-LAST:event_Line_constActionPerformed

private void Line_AscActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Line_AscActionPerformed
    arreglo.clear();
    arreglo_pronostico.clear();
    ldco.setInicio(null);
    AsignarArreglo_Asc();
}//GEN-LAST:event_Line_AscActionPerformed

private void Metodo_multipleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Metodo_multipleActionPerformed

    if (Metodo_multiple.isSelected()) {
        EEPeriodo.setEnabled(false);
    } else {
        EEPeriodo.setEnabled(true);
    }
    JOptionPane.showMessageDialog(null, "Ahora dale al boton generar tabla de manera obligatoria \nAsi evitamos errores de tu parte");
}//GEN-LAST:event_Metodo_multipleActionPerformed

private void Menu_MultipleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Menu_MultipleActionPerformed
    try {
        GENERAR_ARREGLO();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Los campos no admiten vacio");
    }
}//GEN-LAST:event_Menu_MultipleActionPerformed

private void MEnu_CiclicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MEnu_CiclicoActionPerformed
    try {
        BUSCAR_ALTOS_BAJOS();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Los campos no admiten vacio");
    }
}//GEN-LAST:event_MEnu_CiclicoActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    dispose();
}//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FRame_Regresion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FRame_Regresion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FRame_Regresion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FRame_Regresion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FRame_Regresion().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner EEPeriodo;
    private javax.swing.JButton GTabla;
    private javax.swing.JMenuItem Line_Asc;
    private javax.swing.JMenuItem Line_const;
    private javax.swing.JMenuItem MEnu_Ciclico;
    private javax.swing.JMenuItem Menu_Multiple;
    private javax.swing.JCheckBoxMenuItem Metodo_multiple;
    private javax.swing.JSpinner PPeriodo;
    private javax.swing.JTable Tabla;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    private void AsignarArreglo_Asc() {
        try {
            ASIGNAR_DATOS_EN_ARREGLO();
            INGRESAR_DATOS_CUADRO_EM_ASC(arreglo);
            MUESTREO_DE_DATOS_CARGADOS();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Los campos no admiten vacio");
        }
    }

    private void AsignarArreglo() {
        try {
            ASIGNAR_DATOS_EN_ARREGLO();

            y_promedio = Estadistica.Promedio(arreglo);
            //System.out.println(Estadistica.DesvSTD(arreglo, y_promedio));
            INGRESAR_DATOS_CUADRO_EM(arreglo);
            MUESTREO_DE_DATOS_CARGADOS();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Los campos no admiten vacio");
        }
    }

    private void INGRESAR_DATOS_CUADRO_EM_ASC(ArrayList arreglo) {
        Double B = Estadistica.VariableB(arreglo);
        Double A = Estadistica.VariableA();
        Double R = Estadistica.VariableR();
        ArrayList arreglo2 = new ArrayList();
        System.out.println("Variables B= " + B + "  A= " + A + "  R= " + R);
        for (int X = 0; X < arreglo.size(); X++) {
            double var_Y = Math.round(B * (X + 1) + A);
            double Y_Y = Double.parseDouble(arreglo.get(X).toString()) - var_Y;
            arreglo2.add(Y_Y);
            double absoluto_EM;
            try {
                absoluto_EM = Math.abs(Double.parseDouble(arreglo2.get(X).toString()) - Double.parseDouble(arreglo2.get(X - 1).toString()));
            } catch (Exception Exception) {
                absoluto_EM = 0;
            }
            System.out.println(X + "  " + arreglo.get(X).toString() + "  " + var_Y + "  " + Y_Y + "  " + absoluto_EM);
            Ingresa_Datos_ESTRUCTURA_DINAMICA(X, Double.parseDouble(arreglo.get(X).toString()), absoluto_EM, Y_Y, var_Y + 2 * Estadistica.DesvSTD(arreglo, var_Y), var_Y - 2 * Estadistica.DesvSTD(arreglo, var_Y));
            ldco.agrega(escal);
        }
        for (int k = arreglo.size(); k < arreglo.size() + 12; k++) {
            double var = Math.round(B * (k + 1) + A);
            arreglo_pronostico.add(var);
        }
    }

    private void INGRESAR_DATOS_CUADRO_EM(ArrayList arreglo) {
        for (int i = 0; i < arreglo.size(); i++) {
            double absoluto;
            try {
                absoluto = Math.abs(Double.parseDouble(arreglo.get(i + 1).toString()) - Double.parseDouble(arreglo.get(i).toString()));
            } catch (Exception Exception) {
                absoluto = 0;
            }
            double Y_Y = Double.parseDouble(arreglo.get(i).toString()) - Math.rint(y_promedio);
            //System.out.println("EM " + absoluto + "Y_y " + Y_Y);
            Ingresa_Datos_ESTRUCTURA_DINAMICA(i, Double.parseDouble(arreglo.get(i).toString()), absoluto, Y_Y, y_promedio + 2 * Estadistica.DesvSTD(arreglo, y_promedio), y_promedio - 2 * Estadistica.DesvSTD(arreglo, y_promedio));
            ldco.agrega(escal);
        }
        for (int k = arreglo.size(); k < arreglo.size() + 12; k++) {
            double var = Math.rint(y_promedio);
            arreglo_pronostico.add(var);
        }
    }

    private void Ingresa_Datos_ESTRUCTURA_DINAMICA(int elemento_periodo, double variableY, double variableEM, double variableY_Ypromedio, double Limite_S, double Limite_I) {
        escal = new EscalaMovil();
        escal.setPeriodo(elemento_periodo);
        escal.setVar_Y(variableY);
        escal.setEM(variableEM);
        escal.setVarY_y(variableY_Ypromedio);
        escal.setLimite_S(Limite_S);
        escal.setLimite_I(Limite_I);
    }

    private void GENERAR_ARREGLO() {
        double varY = 0, varX_1 = 0, varX_2 = 0, varY2 = 0, var_X1_2 = 0, var_X2_2 = 0, varYX_1 = 0, varYX_2 = 0, varX_1X_2 = 0;
        for (int P = 0; P < getMiTabla().getRowCount(); P++) {
            double temp_varY = Double.parseDouble(getMiTabla().getValueAt(P, 1).toString());
            double temp_varX_1 = Double.parseDouble(getMiTabla().getValueAt(P, 2).toString());
            double temp_varX_2 = Double.parseDouble(getMiTabla().getValueAt(P, 3).toString());
            varY += temp_varY;
            varX_1 += temp_varX_1;
            varX_2 += temp_varX_2;
            varY2 += Math.pow(temp_varY, 2);
            var_X1_2 += Math.pow(temp_varX_1, 2);
            var_X2_2 += Math.pow(temp_varX_2, 2);
            varYX_1 += temp_varY * temp_varX_1;
            varYX_2 += temp_varY * temp_varX_2;
            varX_1X_2 += temp_varX_1 * temp_varX_2;
        }
        double matriz_original[][] = new double[3][3];
        double vector[] = new double[3];
        matriz_original[0][0] = getMiTabla().getRowCount();
        matriz_original[0][1] = varX_1;
        matriz_original[0][2] = varX_2;

        vector[0] = varY;

        matriz_original[1][0] = varX_1;
        matriz_original[1][1] = var_X1_2;
        matriz_original[1][2] = varX_1X_2;

        vector[1] = varYX_1;

        matriz_original[2][0] = varX_2;
        matriz_original[2][1] = varX_1X_2;
        matriz_original[2][2] = var_X2_2;

        vector[2] = varYX_2;

        RESOLVER_ARREGLO(matriz_original, vector);
    }

    private void RESOLVER_ARREGLO(double[][] matriz_original, double[] vector) {
        double determinante_original;
        ArrayList arreglo_temp = new ArrayList();
        determinante_original = Cramer.Llamar_determinante(matriz_original);
        double matriz_temp[][] = new double[4][4];
        double detTemp;
        for (int i = 0; i < 3; i++) {
            matriz_temp = Cramer.sustituye(matriz_original, vector, i);
            detTemp = Cramer.Llamar_determinante(matriz_temp);
            arreglo_temp.add(((float) detTemp / (float) determinante_original));
        }
        //Mostrar_datos_multiple();
        String cadenaX = "variables X= " + (Double.parseDouble(arreglo_temp.get(0).toString()));
        System.out.println(cadenaX);
        String cadenaY = "variables Y= " + (Double.parseDouble(arreglo_temp.get(1).toString()));
        System.out.println(cadenaY);
        String cadenaZ = "variables Z= " + (Double.parseDouble(arreglo_temp.get(2).toString()));
        System.out.println(cadenaZ);
        JOptionPane.showMessageDialog(null, cadenaX + "\n" + cadenaY + "\n" + cadenaZ, "RESULTADOS", JOptionPane.INFORMATION_MESSAGE);
    }

    private void MUESTREO_DE_DATOS_CARGADOS() {
        System.out.println("Tabla escala movil generada......");
        double temp_EM = 0;
        for (int o = 0; o < getMiTabla().getRowCount() * (getMiTabla().getColumnCount() - 1); o++) {
            NodoDoble auxiliar = ldco.busca(o);
            if (auxiliar != null) {
                System.out.println(auxiliar.getNodo().getPeriodo() + "  " + auxiliar.getNodo().getVar_Y() + "  " + auxiliar.getNodo().getVarY_y() + "  " + auxiliar.getNodo().getEM());
                dataset.setValue(auxiliar.getNodo().getVar_Y(), nombre_linea, String.valueOf(auxiliar.getNodo().getPeriodo() + 1));
                temp_EM += auxiliar.getNodo().getEM();
                dataset.setValue(auxiliar.getNodo().getVarY_y(), "Escala movil", String.valueOf(auxiliar.getNodo().getPeriodo() + 1));
            }
        }
        //System.out.println("total escala"+temp_EM+"  totales"+(arreglo.size()-1));
        for (int o = 0; o < getMiTabla().getRowCount() * (getMiTabla().getColumnCount() - 1); o++) {
            //dataset.setValue(temp_EM / (arreglo.size()-1), "Escala movil-media", String.valueOf(o + 1));
            dataset.setValue(2.66 * temp_EM / (arreglo.size() - 1), "LSC", String.valueOf(o + 1));
            dataset.setValue(-2.66 * temp_EM / (arreglo.size() - 1), "LIC", String.valueOf(o + 1));
        }
        GENERAR_VENTANA();
        GENERAR_PRONOSTICO();
    }

    private JFreeChart createChart(CategoryDataset dataset, TiposDeGrafico tipo) {
        // Hacemos la ventana con el gráfico
        // Los tres booleans del final:
        // - Si se deben mostrar las leyendas con el nombre
        // - Si se deben mostrar tooltip al poner el ratón sobre las barras
        // - Si se muestran las url
        JFreeChart chart;
        switch (tipo) {
            case AreaChart:
                chart = ChartFactory.createAreaChart(tipo_cuadro, periodo,
                        valorY, dataset, PlotOrientation.VERTICAL, true,
                        true, true);
                break;
            case BarChart:
                chart = ChartFactory.createBarChart(tipo_cuadro, periodo,
                        valorY, dataset, PlotOrientation.VERTICAL, true,
                        true, true);
                break;
            case BarChart3D:
                chart = ChartFactory.createBarChart3D(tipo_cuadro, periodo,
                        valorY, dataset, PlotOrientation.VERTICAL, true,
                        true, true);
                break;
            case LineChart:
                chart = ChartFactory.createLineChart(tipo_cuadro, periodo,
                        valorY, dataset, PlotOrientation.VERTICAL, true,
                        true, true);
                break;
            case LineChart3D:
                chart = ChartFactory.createLineChart3D(tipo_cuadro, periodo,
                        valorY, dataset, PlotOrientation.VERTICAL, true,
                        true, true);
                break;
            case MultiplePieChart:
                chart = ChartFactory.createMultiplePieChart(tipo_cuadro, dataset,
                        TableOrder.BY_COLUMN, true, true, true);
                break;
            case MultiplePieChart3D:
                chart = ChartFactory.createMultiplePieChart3D(tipo_cuadro, dataset,
                        TableOrder.BY_COLUMN, true, true, true);
                break;
            default:
                chart = null;
        }
        return chart;
    }

    private void Mostrar_datos_multiple() {
        for (int o = 0; o < getMiTabla().getRowCount(); o++) {
            dataset.setValue(Integer.parseInt(getMiTabla().getValueAt(o, 1).toString()), "Variable X1", String.valueOf(getMiTabla().getValueAt(o, 2)));
            dataset.setValue(Integer.parseInt(getMiTabla().getValueAt(o, 1).toString()), "Variable X2", String.valueOf(getMiTabla().getValueAt(o, 3)));
        }

        GENERAR_VENTANA();
    }

    private void GENERAR_PRONOSTICO() {
        Pronostico obj = new Pronostico(arreglo_pronostico);
        obj.show();
    }

    private void BUSCAR_ALTOS_BAJOS() {
        arreglo.clear();
        arreglo_pronostico.clear();
        ldco.setInicio(null);
        ASIGNAR_DATOS_EN_ARREGLO();
        double mayor1 = VerMayor(arreglo);
        double menor1 = VerMenor(arreglo);
        System.out.println(mayor1);
    }

    private void ASIGNAR_DATOS_EN_ARREGLO() {
        for (int j = 1; j < getMiModelo().getColumnCount(); j++) {
            for (int k = 0; k < getMiModelo().getRowCount(); k++) {
                //System.out.println("..." + getMiModelo().getValueAt(k, j));
                arreglo.add(getMiModelo().getValueAt(k, j));
            }
        }
    }

    private double VerMayor(ArrayList arreglo) {
        double retorno = 0;
        for (int i = 0; i < arreglo.size(); i++) {
            if (Double.parseDouble(arreglo.get(i).toString()) > retorno) {
                retorno = Double.parseDouble(arreglo.get(i).toString());
            }
        }
        return retorno;
    }

    private double VerMenor(ArrayList arreglo) {
        double retorno = 0;
        for (int i = 0; i < arreglo.size(); i++) {
            if (Double.parseDouble(arreglo.get(i).toString()) < retorno) {
                retorno = Double.parseDouble(arreglo.get(i).toString());
            }
        }
        return retorno;
    }

    enum TiposDeGrafico {

        AreaChart, BarChart, BarChart3D, LineChart, LineChart3D, MultiplePieChart, MultiplePieChart3D
    }
}
